package com.example.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.resource.InvestorList;
import com.yijiu.trb.R;

/**
 * 投资人列表适配器
 * 
 * @author TangChao
 */
public class InvestorListAdapter extends MyBaseAdapter {

	private View progressBar;

	private Context context;

	public InvestorListAdapter(List<InvestorList> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		if (isShowProgress) {
			return list.size() + 1;
		}
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		if (isShowProgress) {
			return null;
		}
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (position == list.size()) {
			if (progressBar == null) {
				progressBar = LayoutInflater.from(context).inflate(R.layout.load_next_page_layout, null);
			}
			return progressBar;
		} else {
			convertView = LayoutInflater.from(context).inflate(R.layout.investor_list_adapter, null);
			TextView userName = (TextView) convertView.findViewById(R.id.user_name);
			TextView realName = (TextView) convertView.findViewById(R.id.real_name);
			TextView rate = (TextView) convertView.findViewById(R.id.rate_get);
			InvestorList investorList = (InvestorList) list.get(position);
			userName.setText(investorList.userName);
			realName.setText(investorList.realName);
			rate.setText(investorList.distributionQuota + "%");
			if (position >= list.size() - 1 && listener != null) {
				listener.onFoot();
			}
			return convertView;
		}
	}
}
